import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 1925. 统计平方和三元组的数目
 * https://leetcode-cn.com/problems/count-square-sum-triples/
 */
public class Solutions_1925 {
    public static void main(String[] args) {
        int n1 = 5;  // output: 2
        int n2 = 10;  // output: 4

        List<Integer> inputs = new ArrayList<>();
        inputs.add(n1);
        inputs.add(n2);

        for (Integer input : inputs) {
            int result = countTriples(input);
            System.out.println(result);
        }
    }

    public static int countTriples(int n) {
        Set<Integer> set = new HashSet<>();
        int res = 0;
        for (int i = 1; i <= n; i++) {
            set.add(i * i);
        }
        for (int num1 : set) {
            for (int num2 : set) {
                // a^2 + b^2 = c^2
                if (set.contains(num1 + num2)) {
                    res ++;
                }
            }
        }
        return res;
    }
}
